package com.ebupt.migu.music.schedule.util;




import java.util.ArrayList;
import java.util.List;

/**
 * @author xuhongsong@cd.ebupt.com
 * @version 1.0
 * @className BeatchUtils
 * @date 2020/7/6 10:37
 */
public class BeatchUtils<T> {
    /**
     *  List 按照长度来分组
     * @param list
     * @param len
     * @return 返回分组后的List
     */
    public  List<List<T>> beatchList(List<T> list, int len){
        int size=list.size();
        List<List<T>> list1=new ArrayList<>();
        if(size<=len){
            list1.add(list);
        }else {
            int total = size % len == 0 ? size / len : (size / len + 1);
            int start = 0;
            int end = start + len;
            for (int i = 0; i < total; i++) {
                list1.add(list.subList(start, end));
                start = end;
                // 给定list集合截取的最大值
                end = Math.min((end + len), size);
            }
        }
        return list1;
    }
}
